<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="include/peizhi.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="${ctx}">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
        
        <title>后台管理中心</title> 
		<link rel="stylesheet" href="${ctx}/css/pintuer.css" /> 
		<link rel="stylesheet" href="${ctx}/css/admin.css" /> 
        <script type="text/javascript" src="${ctx}/js/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="${ctx}/js/pagehoutai.js"></script>
    </head>
  	<body style="background-color:#f2f9fd;"> 
	  <jsp:include page="include/header.jsp" flush="true"/>
	  <div class="admin"> 
	  	<div class="panel admin-panel margin-top" id="add" >
		  <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 增加内容</strong></div>
		  <div class="body-content" id='addBanner'>
			  <table border="6" >
				  <form method="post" class='formAdd' class="form-x" action="${ctx}/adv/banner"> 
					  	<tr style="display:block;margin:20px 0">
					  		<td><label>标题：</label> <input type="text" id='title' value="${banner.title}" name="title" placeholder="请输入标题" /></td><br/>
					  	</tr>
					  	<tr style="display:block;margin:20px 0">
					  		<td><label>图片：</label> <input type="file" value="" class='imageflle'  placeholder="请选择文件" />
					  		<input onclick="imageAdd()" type="button" class='shangchuan' value="上传"/><input type="hidden" id='headimg' name='imageurl'  value="${banner.imageurl}"></td><br/>
					  	</tr>
					  	<tr style="display:block;margin:20px 0">
					  		 <td><label>描述：</label><textarea type="text" id='content' name="content" style="height:20px;">${banner.content}</textarea></td><br/>
					  	</tr>
					  	<tr style="display:block;margin:20px 0">
					  		 <td><label>排序：</label><input type="text" id='numb' name="numb" value="${banner.numb}"/></td><br/>
					  	</tr>
					  	<tr style="display:block;margin:20px 0">
					  		 <td><label>url地址：</label><input type="text" id='url' name="url" value='${banner.url}' placeholder="上传指定url地址"/></td><br/>
					  	</tr>
					  	<tr style="display:block;margin:20px 0">
					  		 <td><input type="hidden" id='id' name="id" value='${banner.id}'/>
					  	<input type="button" onclick="submintForm()" value='提交'></td><br/>
					  	</tr>
				  </form>
			  </table>
		 </div>
		</div>
	  </div> 
 </body>
 <script type="text/javascript">
 //添加banner
 function addadv(){
 	var html = $("#addBanner").html();
 	alert(html,'submintForm()','提交');
 }
 //上传图片
function imageAdd(){
 		//上传图片
		var fd = new FormData();
			fd.append("upload", 1);
			fd.append("image",$(".imageflle").get(0).files[0]);//id为上传图片的id字符串image应该是后台接收的对象
		$.ajax({
				url: "${ctx}/Upload/image2",
				type: "POST",
				processData: false,
				contentType: false,//禁止ajax识别类型
				data: fd,
				success: function(data) {
					//console.log(d);
					//background:url(icon.jpg) no-repeat left center; width:200px; height:30px;
					if(data!='' && data!=null){
						$(".shangchuan").attr("onclick","");
						$(".shangchuan").val("上传成功","");
						$("input[name='imageurl']").get(0).value=data;
						//$("#imagezhanshi").attr("style","background:url(${ctx}/upload/img/logo.jpg)no-repeat no-repeat center; width:200px; height:30px;");
					}else{
						alert("上传不成功请重新上传");
					}
				}
			});
 	}
 	function submintForm(){
 	var parm = {'title':$("input[name='title']").get(0).value,
 				'imageurl':$("input[name='imageurl']").get(0).value,
 				'content':$("textarea[name='content']").get(0).value,
 				'numb':$("input[name='numb']").get(0).value,
 				'url':$("input[name='url']").get(0).value,
 				'id':$("#id").val()};
 		$.ajax({
 			url:"${ctx}/adv/banner",
 			type:"post",
 			data:parm,
 			success:function(data){
 				//doOk();
 				if(data=='1'){
	 				var id = $("#id").val();
	 				if(id!='' && id!=null){
	 					$("#id").val('0');
	 					alert("修改成功");
	 				}else{
	 					alert("添加成功");
	 				}
	 			}else{
	 				var id = $("#id").val();
	 				if(id!='' && id!=null){
	 					$("#id").val('0');
	 					alert("修改失败");
	 				}else{
	 					alert("添加失败");
	 				}
 				}
 				
 			}
 		});
 	}
</script>
</html>